package com.hui.server.controller;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.hui.server.entity.Employee;
import com.hui.server.entity.Salary;
import com.hui.server.service.EmployeeService;
import com.hui.server.service.SalaryService;
import com.hui.server.util.RespPageBean;
import com.hui.server.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.builder.ToStringExclude;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @BelongsProject: yeb
 * @BelongsPackage: com.hui.server.controller
 * @Author: HUI
 * @CreateTime: 2022-04-16 14:45
 * @Description: 员工套账
 */


@Api(tags = "SalarySobCfgController")
@RequestMapping("/salary/sobcfg")
@RestController
public class SalarySobCfgController {


    private final SalaryService salaryService;

    private final EmployeeService employeeService;

    @Autowired
    public SalarySobCfgController(SalaryService salaryService, EmployeeService employeeService) {
        this.salaryService = salaryService;
        this.employeeService = employeeService;
    }

    @ApiOperation(value = "获取所有员工套账")
    @GetMapping("/")
    public RespPageBean getEmployeeWithSalary(@RequestParam(defaultValue = "1") Integer currentPage, @RequestParam(defaultValue = "10") Integer size) {
        return employeeService.getEmployeeWithSalary(currentPage, size);
    }

    @ApiOperation(value = "获取所有工资套账")
    @GetMapping("/salaries")
    public List<Salary> getAllSalary() {
        return salaryService.list();
    }

    @ApiOperation(value = "更新员工套账")
    @PutMapping("/")
    public Result<?> updateEmployeeSalary(Integer eid, Integer sid) {
        boolean update = employeeService.update(new UpdateWrapper<Employee>().set("salaryId", sid).eq("id", eid));
        return update ?
                Result.success() :
                Result.error(String.valueOf(HttpStatus.INTERNAL_SERVER_ERROR.value()), "更新失败！");
    }
}
